"""
@Author  : 康帅
@Time    : 2021/3/16 10:42
@Function: 克隆模式(原型模式)：深拷贝与浅拷贝(宠物店案例)
"""
from copy import copy, deepcopy


class PetStore:
    """ 宠物店 """

    def __init__(self, name):
        self.__name = name
        self.__pet_list = []

    def set_name(self, name):
        self.__name = name

    def show_my_self(self):
        print("%s 宠物店有以下宠物：" % self.__name)
        for pet in self.__pet_list:
            print(pet + "\t", end="")
        print()

    def add_pet(self, pet):
        self.__pet_list.append(pet)


if __name__ == '__main__':
    petter = PetStore("Petter")
    petter.add_pet("小狗 Coco")
    print("父本 petter：", end="")
    petter.show_my_self()
    print("------------1--------------")

    """ 浅拷贝只拷贝引用类型对象的指针（指向），而不拷贝引用类型对象指向的值；深拷贝则同时拷贝引用类型对象及其指向的值 """
    # 深拷贝又称为安全模式
    petter1 = deepcopy(petter)
    petter1.add_pet("小猫 Amy")
    print("副本petter1：", end="")
    petter1.show_my_self()
    print("父本petter：", end="")
    petter.show_my_self()
    print("------------2--------------")

    petter2 = copy(petter)
    petter2.add_pet("小兔 Kim")
    print("副本petter2：", end="")
    petter2.show_my_self()
    print("父本petter：", end="")
    petter.show_my_self()
